package com.xt.back.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xt.back.constant.ResultDTO;
import com.xt.back.entity.Relation;
import com.xt.back.entity.Reward;
import com.xt.back.service.IRewardService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 奖励信息表 前端控制器
 * </p>
 *
 * @author leotong
 * @since 2022-04-03
 */
@CrossOrigin
@RestController
@RequestMapping("/back/reward")
@AllArgsConstructor
public class RewardController {

    private final IRewardService rewardService;

    @PostMapping("/add")
    public ResultDTO<Boolean> addReward(@RequestBody Reward reward){
        return ResultDTO.success(rewardService.save(reward));
    }

    @GetMapping("/remove")
    public ResultDTO<Boolean> deleteReward(int id){
        return ResultDTO.success(rewardService.removeById(id));
    }

    @PostMapping("/update")
    public ResultDTO<Boolean> updateReward(@RequestBody Reward reward){
        return ResultDTO.success(rewardService.updateById(reward));
    }

    @PostMapping("/getRewardByPage")
    public ResultDTO<Page<Reward>> getRewardByPage(@RequestBody Reward reward){
        return ResultDTO.success(rewardService.getRewardByPage(reward));
    }

    @GetMapping("/getAllReward")
    public ResultDTO<List<Reward>> getAllRewardn(){
        return ResultDTO.success(rewardService.list());
    }
}
